package views;

import views.panels.PanelGeneral;
import logicBusiness.AsignaturaBL;
import logicBusiness.CursoBL;
import logicBusiness.GradoBL;
import java.awt.BorderLayout;
import java.util.List;
import javax.swing.DefaultComboBoxModel;

/**
 *
 * @author sebastian
 */
public class InterfazCrearHorario extends javax.swing.JFrame {

    private GradoBL boG = new GradoBL();
    private AsignaturaBL boA = new AsignaturaBL();
    private CursoBL boC = new CursoBL();

    /** Creates new form InterfazCrearHorario */
    public InterfazCrearHorario() {
        initComponents();
        PanelGeneral panel = new PanelGeneral();
        this.add(panel, BorderLayout.SOUTH);
        cargarComboGrados();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        CBGrados = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        CBCursos = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        BAgregarAsig = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        CBAsignaturas = new javax.swing.JComboBox();
        BEliminarAsig = new javax.swing.JButton();
        SPHorario = new javax.swing.JScrollPane();
        THorario = new javax.swing.JTable();
        BGuardarHorario = new javax.swing.JButton();
        BSalir = new javax.swing.JButton();

        setResizable(false);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(0, 0, 255));
        jLabel1.setText("BUSCAR CURSO");

        jLabel2.setText("Grado:");

        CBGrados.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                CBGradosMouseClicked(evt);
            }
        });
        CBGrados.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CBGradosActionPerformed(evt);
            }
        });

        jLabel3.setText("Curso:");

        jLabel4.setText("Horario");

        BAgregarAsig.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BAgregarAsig.setText("Agregar Asignatura");

        jLabel6.setText("Lista de asignaturas");

        BEliminarAsig.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BEliminarAsig.setText("Eliminar Asignatura");

        THorario.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "Hora", "Lunes", "Martes", "Miercoles", "Jueves", "Viernes"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        SPHorario.setViewportView(THorario);

        BGuardarHorario.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BGuardarHorario.setText("Guardar Horario Para Este Curso");

        BSalir.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        BSalir.setText("Salir");
        BSalir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                BSalirActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel1)
                                    .addGroup(layout.createSequentialGroup()
                                        .addComponent(jLabel2)
                                        .addGap(73, 73, 73)
                                        .addComponent(CBGrados, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 61, Short.MAX_VALUE)
                                        .addComponent(jLabel3)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                        .addComponent(CBCursos, javax.swing.GroupLayout.PREFERRED_SIZE, 144, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGap(12, 12, 12)))
                                .addGap(204, 204, 204))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel6)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(CBAsignaturas, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(BAgregarAsig, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE)
                            .addComponent(BEliminarAsig, javax.swing.GroupLayout.DEFAULT_SIZE, 269, Short.MAX_VALUE))
                        .addGap(20, 20, 20))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addGap(10, 10, 10))
                            .addComponent(SPHorario, javax.swing.GroupLayout.DEFAULT_SIZE, 984, Short.MAX_VALUE))
                        .addContainerGap())))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addComponent(BGuardarHorario, javax.swing.GroupLayout.PREFERRED_SIZE, 286, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 317, Short.MAX_VALUE)
                .addComponent(BSalir, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(55, 55, 55))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2)
                            .addComponent(CBGrados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(CBCursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel3))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel6)
                            .addComponent(CBAsignaturas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(BAgregarAsig)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(BEliminarAsig)))
                .addGap(26, 26, 26)
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(SPHorario, javax.swing.GroupLayout.PREFERRED_SIZE, 252, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(30, 30, 30)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(BSalir)
                    .addComponent(BGuardarHorario))
                .addContainerGap(36, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void BSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BSalirActionPerformed
        // TODO add your handling code here:
        this.setVisible(false);
    }//GEN-LAST:event_BSalirActionPerformed

    private void CBGradosMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_CBGradosMouseClicked
        /* cargarComboAsignaturas();
        cargarComboCursos();*/
    }//GEN-LAST:event_CBGradosMouseClicked

    private void CBGradosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CBGradosActionPerformed
        cargarComboAsignaturas();
        cargarComboCursos();
    }//GEN-LAST:event_CBGradosActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new InterfazCrearHorario().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BAgregarAsig;
    private javax.swing.JButton BEliminarAsig;
    private javax.swing.JButton BGuardarHorario;
    private javax.swing.JButton BSalir;
    private javax.swing.JComboBox CBAsignaturas;
    private javax.swing.JComboBox CBCursos;
    private javax.swing.JComboBox CBGrados;
    private javax.swing.JScrollPane SPHorario;
    private javax.swing.JTable THorario;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel6;
    // End of variables declaration//GEN-END:variables

    private void cargarComboGrados() {
        List l = boG.consultarGrados();
        DefaultComboBoxModel modelo = new DefaultComboBoxModel();
        modelo.removeAllElements();
        for (int i = 0; i < l.size(); i++) {
            modelo.addElement(l.get(i));

        }
        CBGrados.setModel(modelo);
    }

    private void cargarComboCursos() {
        int idGrado = CBGrados.getSelectedIndex();
        List l = boC.consultarCursosGrado(idGrado);
        DefaultComboBoxModel modelo = new DefaultComboBoxModel();
        for (int i = 0; i
                < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }
        CBCursos.setModel(modelo);
    }

    private void cargarComboAsignaturas() {
        int idGrado = CBGrados.getSelectedIndex();
        List l = boA.consultarAsignaturasGrado(idGrado);
        DefaultComboBoxModel modelo = new DefaultComboBoxModel();
        for (int i = 0; i
                < l.size(); i++) {
            modelo.addElement(l.get(i) + "");
        }
        CBAsignaturas.setModel(modelo);
    }
}
